from mwclient import Site
import os

# 登录


site = Site("wiki.biligame.com/ap", path="/", scheme="https")
site.login(
    cookies={
        "SESSDATA": "36c8f1f5%2C1771608973%2C6522d%2A81CjAnv6xBLO4qrgZSQ4LXMh8kxu556yhNuz752DCiXm4HL3bNBdXKEQHL7wL0v7X33wgSVkZEUG53NEJpMVpObHRFN1Q5LTlEYy1oRl8ta1l5eFBJSFdlUEdFT2Z0dEdmeUs0MWhvNE0tVGhWdGxDbDdrSTRteFJXM3FGUHNDN2VmeFhNcjZWcjN3IIEC"
    }
)  # 记得替换
# site.users用于批量获取用户信息，此处只获取一个
user_info = next(site.users([site.username]))
print("用户id：", site.username, "用户组：", user_info["groups"])


# 更新hero数据
def updateHero():
    for name in [
        f for f in os.listdir("hero") if os.path.isfile(os.path.join("hero", f))
    ]:
        with open(
            "hero/" + name, "r", encoding="utf-8"
        ) as file:  # 要覆盖到WIKI的json文件
            data = file.read()
            page = site.pages["模块:Hero/" + name]  # 要覆盖数据页面
            page.save(data, summary="更新角色数据")
            print("角色" + name + "数据更新成功！")


updateHero()
